package com.cet.programmercarl.algorithmperformancanalysis;

/**
 * @program: algorithm
 * @description: 求x^n
 * @author: 陈恩涛
 * @create: 2021-12-28 16:05
 **/
public class Test01 {

    static int function3(int x, int n) {

        if (n == 0) {
            return 1;
        }
        if (n % 2 == 1) {
            return function3(x, n / 2) * function3(x, n / 2)*x;
        }
        return function3(x, n / 2) * function3(x, n / 2);
    }

    static int function4(int x, int n) {
        if (n == 0) {
            return 1;
        }
        int t = function4(x, n / 2);
        if (n % 2 == 1) {
            return t * t * x;
        }
        return t * t;
    }

    public static void main(String[] args) {
        System.out.println(function3(5, 6));
        System.out.println(function4(5, 6));
    }
}
